<?php
// +----------------------------------------------------------------------
// | 卡券
// +----------------------------------------------------------------------
// | Copyright (c) 2015-2024 http://www.yicmf.com, All rights reserved.
// +----------------------------------------------------------------------
// | Author: 微尘 <yicmf@qq.com>
// +----------------------------------------------------------------------
namespace app\controller\api\v3;

use app\event\app\Tbk;
use app\event\ucenter\Feedback as FeedbackEvent;
use app\model\app\ExchangeCoupon as ExchangeCouponModel;
use app\model\app\ExchangeCouponTab as ExchangeCouponTabModel;
use app\model\app\ExchangeCouponGroup as ExchangeCouponGroupModel;
use app\event\app\ExchangeCoupon as ExchangeCouponEvent;
use app\model\app\TbkOrder as TbkOrderModel;

class Other extends Common
{


    public function life()
    {
        $content = $this->request->param('content');
        $tbk = new Tbk();
        $re  = $tbk->parseContent($content,$this->user);
        return $this->successAjax($re);
    }

    public function order()
    {
        if ($this->request->isPost()) {

            $data = $this->request->param();

            $result = $this->validate($this->request->post(), 'app\validate\ucenter\Feedback');
            if (true !== $result) {
                $data['code'] = 20002;
                $data['message'] = $result;
            } else {
                $user_event = new FeedbackEvent();
                $data = $user_event->add($this->request->param(), $this->user);
            }

            return $this->autoAjax($data);
        } else {
            $info = [];
            $info['lists']['tbk'] = '淘宝/天猫';
            $info['lists']['jd'] = '京东';
            $info['lists']['pdd'] = '拼多多';
            $info['tips'] = '暂时支持一单提交';
            $info['image'] = 1;
            return $this->successAjax($info);
        }

    }


    /**
     * 优惠券主页
     */
    public function home()
    {
        $data['channel']['tbk'] = 1;
        $data['channel']['pdd'] = 0;
        $data['channel']['jd'] = 0;
        $avg = TbkOrderModel::where('status',1)->order('id DESC')->limit(10)->avg('income_rate');
        $data['show_text_tips'] = '近期购物平均返'.round($avg,2).'%';
        $data['fee']['tbk'] = config('tbk.add_fee');
        $data['explosiveGoods'] = [];
        $tab_id  = $this->request->param('tab_id',7);
        $page  = $this->request->param('page',1);
        //榜单类型：1.实时榜 ，2.全天榜，3.热推榜，7.综合热搜榜，8.原实时榜2.0（已升级为实时榜），9.必推榜，11.昨日销量榜，12.7日销量榜，13.30日销量榜，14.去年同期销量榜，15.低价高佣榜。红色为2024/05/15新增榜单
        $data['tabs'][] = ['id'=>7,'name'=>'综合榜'];
        $data['tabs'][] = ['id'=>1,'name'=>'实时榜'];
        $data['tabs'][] = ['id'=>15,'name'=>'高佣榜'];
        $data['tabs'][] = ['id'=>11,'name'=>'昨日榜'];
        $data['tabs'][] = ['id'=>9,'name'=>'必推榜'];
        $tbk = new Tbk();
        $re = $tbk->getRankingList($tab_id,$page);
        if ($re['code'] == 0)
        {
            $data['topGoods']= $re['data'];
        }
        return $this->successAjax($data);
    }

    /**
     * 优惠券主页
     */
    public function create()
    {
        $event = new ExchangeCouponEvent();
        $data = $event->order($this->request->param(),$this->user);
        return $this->autoAjax($data);
    }


}
